/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.ParameterizedType;
import com.sun.javadoc.Type;

/**
 * Implementation of {@link ParameterizedType}
 *
 * @author Chad Retz
 */
@XmlType(name = "parameterizedType")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public class ParameterizedTypeImpl extends TypeImpl implements ParameterizedType {

    //exposed fields
    
    @Expose
    private String containingType;

    @Expose
    private String[] interfaceTypes;

    @Expose
    private String superclassType;

    @Expose
    private String[] typeArguments;
    
    //non-exposed fields
    
    private transient Type containingTypeLoaded;
    
    private transient Type[] interfaceTypesLoaded;
    
    private transient Type superclassTypeLoaded;
    
    private transient Type[] typeArgumentsLoaded;
    
    //ParameterizedType interface impl
    
    @Override
    public Type containingType() {
        if (containingTypeLoaded == null) {
            containingTypeLoaded = getContext().getType(containingType);
        }
        return containingTypeLoaded;
    }
    
    @Override
    public Type[] interfaceTypes() {
        if (interfaceTypesLoaded == null) {
            interfaceTypesLoaded = getContext().getTypes(interfaceTypes);
        }
        return interfaceTypesLoaded;
    }
    
    @Override
    public Type superclassType() {
        if (superclassTypeLoaded == null) {
            superclassTypeLoaded = getContext().getType(superclassType);
        }
        return superclassTypeLoaded;
    }
    
    @Override
    public Type[] typeArguments() {
        if (typeArgumentsLoaded == null) {
            typeArgumentsLoaded = getContext().getTypes(typeArguments);
        }
        return typeArgumentsLoaded;
    }
    
    //other accessors
    
    public String getContainingType() {
        return containingType;
    }
    
    public void setContainingType(String containingType) {
        this.containingType = containingType;
    }
    
    public String[] getInterfaceTypes() {
        return interfaceTypes;
    }
    
    public void setInterfaceTypes(String[] interfaceTypes) {
        this.interfaceTypes = interfaceTypes;
    }
    
    public String getSuperclassType() {
        return superclassType;
    }
    
    public void setSuperclassType(String superclassType) {
        this.superclassType = superclassType;
    }
    
    public String[] getTypeArguments() {
        return typeArguments;
    }
    
    public void setTypeArguments(String[] typeArguments) {
        this.typeArguments = typeArguments;
    }
}
